from sklearn.ensemble import RandomForestRegressor
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
import numpy as np

class ProductivityModel:
    def __init__(self):
        self.model = RandomForestRegressor(n_estimators=100, random_state=42)

    def train(self, X, y):
        """训练模型"""
        X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
        self.model.fit(X_train, y_train)
        preds = self.model.predict(X_test)
        print(f"模型RMSE: {np.sqrt(mean_squared_error(y_test, preds)):.2f}")
        return self.model

    def predict(self, future_data):
        """预测未来趋势"""
        return self.model.predict(future_data)